package com.jyk.blog.service.impl;

import com.jyk.blog.mapper.BlogMapper;
import com.jyk.blog.po.Blog;
import com.jyk.blog.service.BlogService;
import com.jyk.blog.service.BlogTagService;
import com.jyk.blog.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BlogServiceImpl implements BlogService {
    @Autowired
    BlogMapper blogMapper;
    @Autowired
    BlogTagService blogTagService;
    @Autowired
    CommentService commentService;
    @Override
    public List<Blog> queryAll() {
        return blogMapper.findAll();
    }

    @Override
    public List<Blog> queryByUser(int id) {
        return blogMapper.findByUserId(id);
    }

    @Override
    public Blog queryById(int id) {
        return blogMapper.findById(id);
    }

    @Override
    public Blog queryByTime(String time, int userId) {
        return blogMapper.findByTime(time, userId);
    }

    @Override
    public List<Blog> queryByType(int typeId) {
        return blogMapper.findByType(typeId);
    }

    @Override
    public void addOne(Blog blog) {
        blogMapper.insertOne(blog);
    }

    @Override
    public void deleteOne(int id) {
        blogTagService.deleteByBlog(id);
        commentService.deleteByBlog(id);
        blogMapper.deleteOne(id);
    }
}
